<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
        }

        .one {
            margin: 80px auto;
            width: 800px;
            height: 50px;
            text-align: center;
            position: relative;
        }

        .one-input {
            margin: 30px 0;
            width: 800px;
            height: 50px;
            line-height: 50px;
            border: 2px solid black;
            border-radius: 15px;
            padding: 0 10px;
            box-sizing: border-box;
            box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.6);
            outline: none;
            font-size: 16px;
        }

        .one-btn {
            position: absolute;
            top: 32px;
            right: 0;
            width: 80px;
            height: 46px;
            border: none;
            border-left: 2px solid black;
            border-radius: 0 13px 13px 0;
            background-color: pink;
            color: rgba(0, 0, 0, 0.8);
            font-weight: 600;
            font-size: 16px;
            cursor: pointer;
            transform: translate(-1px);
        }

        .two {
            width: 800px;
            border: 2px solid black;
            margin: auto;
            border-radius: 15px;
            box-sizing: border-box;
            box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.6);
            background-color: #f0efec;
        }

        .two-div {
            width: 100%;
            height: 50px;
            border-bottom: 2px solid black;
            border-radius: 15px 15px 0 0;
            font-weight: bold;
            display: flex;
            align-items: center;
            font-size: 18px;
        }

        .two-btn {
            width: 130px;
            height: 100%;
            border: none;
            border-right: 2px solid black;
            border-radius: 13px 0 0 0;
            background-color: rgb(0, 224, 183);
            font-weight: bold;
            font-size: 15px;
            margin-right: 10px;
            cursor: pointer;
            color: #000000a3;
        }

        .two-ul {
            width: 100%;
            border-radius: 13px;
            box-sizing: border-box;
            padding: 40px 125px;
        }

        .ul-lis {
            display: flex;
            flex-wrap: nowrap;
            justify-content: space-between;
            border: 3px solid black;
            box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.6);
            border-radius: 10px;
            height: 60px;
            align-items: center;
            box-sizing: border-box;
            padding: 0 15px;
            margin: 15px;
        }

        .ul-lis:nth-child(2n) {
            background-color: rgba(127, 255, 212, 0.532);
        }

        .ul-lis:nth-child(2n+1) {
            background-color: rgba(222, 184, 135, 0.329);
        }

        .ul-lis:last-child {
            margin: 0;
        }

        .ul-ipt {
            cursor: pointer;
        }

        .ul-sp {
            display: inline-block;
            width: 200px;
            color: #000000b5;
            font-weight: bold;
            margin-left: 10px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .ul-btn {
            width: 30px;
            height: 30px;
            border-radius: 10px;
            font-size: 26px;
            color: rgba(0, 0, 0, 0.582);
            cursor: pointer;
        }

        .box {
            width: 200px;
            border: 2px solid black;
            box-sizing: border-box;
            box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.6);
            border-radius: 8px;
            position: absolute;
            top: 210px;
            left: 8%;
            text-align: center;
        }

        .box li {
            height: 50px;
            line-height: 50px;
            border: 2px solid black;
        }

        .box li:nth-child(n+2) {
            cursor: pointer;
        }

        .Underline {
            text-decoration-line: line-through;
        }
    </style>
    <!-- 引入 layui.css -->
    <link href="//unpkg.com/layui@2.11.2/dist/css/layui.css" rel="stylesheet">
</head>

<body>
    <div class="one">
        <input type="text" name="" placeholder="新增待办事项..." class="one-input">
        <button class="one-btn" onclick="ipt_add()">提交</button>
    </div>
    <div class="two">
        <div class="two-div">
            <button class="two-btn">全部标记为完成</button>
            <span>今日事今日毕，勿将今事待明日！</span>
        </div>
        <ul class="two-ul">

        </ul>
    </div>
    <ul class='box'>
        <li style="background-color: rgba(20, 214, 214, 0.404);">开</li>
        <li style="background-color: rgba(216, 112, 147, 0.623);" onclick="arrs()">全部</li>
        <li onclick="falg_a()">进行中</li>
        <li onclick="falgs()">已完成</li>
        <li onclick="del()">清除全部</li>
    </ul>
    <!-- CDN引⼊JQuery -->
    <script src="https://code.jquery.com/jquery-3.7.1.js"></script>
    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.11.2/dist/layui.js"></script>
    <script>
        window.onload = () => {
            datas()
            $('.two-ul').on('click', two_ul)
            layer.msg('渲染成功', { icon: 6 })
        }
        // 数据
        const getdata = (key) => {
            const data = localStorage.getItem(key)
            if (data) {
                let b = [...JSON.parse(data)]
                return b
            }
            return []
        }
        var data = getdata('data')
        // 添加
        function ipt_add() {
            let one_input = $('.one-input').val()
            if (!data.some(item => item.Data == one_input) && one_input !== '') {
                let arr = {
                    Data: one_input,
                    falg: false,
                }
                data.push(arr)
                localStorage.setItem('data', JSON.stringify(data))
                datas()
                layui.use(layer.msg('添加成功', { icon: 6 }))
            } else if (data.some(item => item.Data == one_input)) {
                layer.msg('添加事项已存在', { icon: 5, anim: 6 })
            } else {
                layer.msg('请输入添加事项', { icon: 5, anim: 6 })
            }
        }
        // 渲染数据
        function datas(a = data) {
            $('.two-ul').html('')
            a.forEach((item, index) => {
                $('.two-ul').append(`
                    <li class="ul-lis">
                        <div>
                            <input class="ul-ipt" type="checkbox" ${item.falg ? 'checked' : ''} data-id='${item.Data}'>
                            <span class="ul-sp ${item.falg ? 'Underline' : ''}">${item.Data}</span>
                        </div>
                        <button class="ul-btn" data-id='${item.Data}'>×</button>
                    </li>
                `)
            })
        }
        // 删除、选中状态
        function two_ul() {
            if (event.target.nodeName == 'BUTTON') {
                let arr = data.findIndex(item => item.Data == event.target.dataset.id)
                data.splice(arr, 1)
                localStorage.setItem('data', JSON.stringify(data))
                datas()
                return layer.msg('删除成功', { icon: 6 })
            }
            if (event.target.nodeName == 'INPUT') {
                let arr = data.find(item => item.Data == event.target.dataset.id)
                arr.falg = event.target.checked
                localStorage.setItem('data', JSON.stringify(data))
                datas()
                if (event.target.checked) {
                    return layer.msg('已完成', { icon: 6 })
                }
                return layer.msg('取消完成', { icon: 6 })
            }
        }
        // 查看已完成状态
        function falgs() {
            let arr = data.filter(item => item.falg)
            datas(arr)
            layer.msg('已完成', { icon: 6 })
        }
        // 清除全部
        function del() {
            data = []
            localStorage.clear()
            datas()
            layer.msg('清除全部', { icon: 6 })
        }
        // 进行中
        function falg_a() {
            let arr = data.filter(item => !item.falg)
            datas(arr)
            layer.msg('进行中', { icon: 6 })
        }
        // 全部
        function arrs() {
            datas()
            layer.msg('全部', { icon: 6 })
        }
    </script>
</body>

</html>